PickElement

導入

v1.0

カテゴリ

選択ユーザ インタフェース

詳細

エレメントの選択をユーザに要求します。

注: このコマンドは、出力引数を使用します。 C# および一部のスクリプト言語(JScript、PerlScript、Python など)は、リファレンスによって渡される引数をサポートしていません。このため、状況に応じた適切な回避策を実行する必要があります。

スクリプト言語の場合、このコマンドは出力引数を取得するために使用できる ISIVTCollection を戻します。

C# の場合は、XSIApplication.ExecuteCommand メソッドを使用してこのコマンドを呼び出すことができます。 ExecuteCommand は、出力引数を C# の System.Object (出力引数の配列を含む)にパック化します(詳細については、「C# からのコマンドの呼び出し」を参照)。

スクリプト構文

PickElement( SelFilter, LeftMessage, MiddleMessage, [PickedElement], [ButtonPressed], SelRegionMode, [ModifierPressed] );

パラメータ

パラメータ タイプ 詳細
SelFilter FilterConstant 選択するエレメントのタイプを指定する選択フィルタ。

デフォルト値: siGenericObjectFilter

LeftMessage 文字列 マウスの左ボタンのステータス バー メッセージ
MiddleMessage 文字列 マウスの中央ボタンのステータス バー メッセージ
PickedElement CollectionItem ユーザが選択したエレメントを戻します。
ButtonPressed Long ユーザがクリックしたマウス ボタンを戻します。

指定可能な値:

説明:

0 マウスの右ボタン(または[Esc]キー)。ユーザが選択セッションを中止したことを意味します。
1 マウスの左ボタン
2 マウスの中央ボタン
SelRegionMode Long 実行する選択の種類

デフォルト値: 0

指定可能な値:

説明:

0 なし(現在のモードを使用)
1 矩形
2 レイキャスト
3 投げ縄
4 フリーフォーム
5 ペイント
ModifierPressed Long ユーザが押した修飾キーを戻します。

指定可能な値:

説明:

0 なし
1 [Shift]修飾キー
2 [Ctrl]修飾キー
3 [Shift]+[Ctrl] 修飾キー

1. JScript の例

/*
        This example illustrates how to set up a pick session to pick only polygons.
*/
NewScene( null, false );
CreatePrim( "Cube", "MeshSurface" );
var rtn = PickElement( "polygon", "Select polygons", "Select polygons", polygons, button, 0 )
logmessage( "Picked Element:" + rtn.Value("PickedElement") +
                " Button:" + rtn.Value("ButtonPressed") +
                " Modifier:" + rtn.Value("ModifierPressed") );
var element = rtn.Value( "PickedElement" );
var button = rtn.Value( "ButtonPressed" );
var modifier = rtn.Value( "ModifierPressed" );
if ( button != 0 ) 
{
var polygons = element.SubComponent.Parent3DObject.ActivePrimitive.Geometry.Facets;
var polygonIndices = element.SubComponent.ElementArray.toArray();
        for ( var i=0; i<polygonIndices.length; i++ )
{
                var currpolygon = polygons( polygonIndices[i] );
                logmessage( currpolygon + " is at index " + currpolygon.Index );
}
}
// Result is something like this (varies as to what gets picked):
// INFO : Picked Element:cube.poly[0,4] Button:1 Modifier:0
// INFO : PolygonFace is at index 0
// INFO : PolygonFace is at index 4
//

2. VBScript の例

' The following example uses PickElement to pick an object of a given type 
' (eg: mesh) then another of another given type (eg: nurbs) to finally 
' parent one to the other
dim parent, child, button, modifier
CreatePrim "Sphere", "NurbsSurface"
Translate , -4.80504207251944, 6.3879907927616, -0.63879907927616, _
siRelative, siView, siObj, siXYZ
CreatePrim "Cone", "MeshSurface"
PickElement "surface_mesh", "Select parent nurbs object", _
"Select parent nurbs object", parent, button,, modifier
if button <> 0 then
        PickElement "polygon_mesh", "Select child mesh object", _
                "Select child mesh object", child, button
        if button <> 0 then
                if modifier = 0 then
                        ParentObj parent, child
                else
                        ParentObj child, parent
                end if
        end if
end if
'The nurbs should now be parent of the mesh (or vice-versa for MMB)

3. JScript の例

/*
        The following example uses PickElement to pick subcomponents on a geometry
*/
CreatePrim( "Sphere", "MeshSurface" );
SetSelFilter("Vertex");
var rtn = PickElement( "point", "Select points", "Select points" );
var button = rtn.Value( "ButtonPressed" );
var points = rtn.Value("PickedElement");
if ( button != 0 ) {
        CreateCluster( points );
}
// A cluster of points should now exist in the sphere.

4. VBScript の例

'
' The following example uses PickElement to select a property of a 3D object
'
dim parent, child, button
CreatePrim "Sphere", "MeshSurface"
set AProperty = PickElement( "property", "Select a property", _
        "Select a property", property, button )
if button <> 0 then
        SelectObj property
end if
' A property of the sphere should now be selected.

5. Python の例

#
#       This example demonstrates how to get values from the
#       output arguments of PickElement.
#
from win32com.client import constants as c
xsi = Application
xsi.NewScene( Application.ActiveProject, 0 )
root = xsi.ActiveSceneRoot
# Set up some models to pick
oMdl = root.AddModel()
oMdl.Name = "Parent1"
oMdl = root.AddModel()
oMdl.Name = "Parent2"
oMdl1 = oMdl.AddModel()
oMdl1.Name = "Child"
oPicked = xsi.PickElement( c.siModelFilter, 'Pick model', 'Pick model' )
xsi.LogMessage( "# of values returned: " + str(oPicked.Count) )
# You can access the output arguments by index (returned sorted
# alphabetically according to parameter name)...
xsi.LogMessage( "Button pressed: " + str(oPicked(0)) )
xsi.LogMessage( "Picked element: " + str(oPicked(2)) )
# ... or access them by name
xsi.LogMessage( "Modifier pressed: " + str(oPicked.Value("ModifierPressed")) )
# Expected result for picking Parent2 with the MMB while 
# holding down alt+shift (# of values will always be 3):
#INFO : # of values returned: 3
#INFO : Button pressed: 2
#INFO : Picked element: Parent2
#INFO : Modifier pressed: 3